package ks.client.gui.admin.user.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.w3c.dom.Document;
import ks.client.UserContext;
import ks.client.ipc.Client;
import ks.client.lobby.Lobby;
import ks.framework.common.Message;

/**
 * Sends a command to get the complete list of active users to the server
 * when the "User List" button is clicked in the user admin commands.
 * 
 * @author Jen_Hunt
 *
 */
public class UserListClickController implements ActionListener{
	
	Lobby lobby;
	
	/**
	 * Constructor for UserListClickController
	 * @param lobby
	 */
	public UserListClickController(Lobby lobby) {
		this.lobby = lobby;		
	}
	
	/**
	 * Constructs and sends the command to get the list of active users.
	 * 
	 */
	public void actionPerformed(ActionEvent e){
			String s = "<admin-command version= \"1.0\" id=\"589a39591271844e3fbe32bbb9281ad9\">" +
			"<user-list/>" + "</admin-command>";
			
			Document d = Message.construct(s);
			Message m = new Message(d);

			//send to server
			UserContext uc = lobby.getUserContext();
			Client c = uc.getClient();
			c.sendToServer(m);
	}
}

